In the session, we calculated the distances to the closest hospitals located within North-Rhine Westphalia (NRW). Still, we did not show how to subset the original file, which contains all hospitals in Germany.
Subset the data file yourself by relying on the spatial information of the filehospital_points.csv and the polygon of North-Rhine Westphalia. How many hospitals are located within the borders of NRW?
hospital_points in the ./data folder and a shapefile of NRW. For NRW, you can use the osmdata syntax.
The default of sf::st_join() will leave you with a ‘left-join’ and returns a data object with all hospitals and matching district information for those which are located within NRW. You can reset the option to perform an ‘inner-join’ and keep only the observation which lay within the predefined area (sf::st_join(x , y, join = "", left = FALSE)).
Did the operationalization of health care provision convince you? Don’t you think it might be more important how many hospitals are close to survey respondents? To test this, we want to calculate the number of hospitals per district in North-Rhine Westphalia. Use the syntax below to prep the hospital data.
Earn extra points by counting not only the number of hospitals but also the sum of hospital beds within a district.nrw_districts <-
sf::read_sf("./data/VG250_KRS.shp") %>%
sf::st_transform(3035) %>%
sf::st_join(nrw, join = sf::st_intersects, left = FALSE)
nrw_hospitals <-
nrw_hospitals %>%
# beds were character, now numeric
dplyr::mutate(beds = as.numeric(beds)) %>%
# replace NAs as zeros for simplification
replace(is.na(.), 0)
dplyr::as_tibble() data frame to use the functions dplyr::group_by() and dplyr::summarise().
dplyr::n() allows summarising the total count of hospitals. sum(beds) for summarizing the bed total per district.